<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>镜像站@Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/admin/plugin/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <script type="text/javascript" src="/admin/js-css/js/mx1.0.js?v=1.3"></script>

    <style type="text/css">
        .layui-table-click {
            background-color:cadetblue !important;
            color:white;
        }

        .layui-btn+.layui-btn {
            margin-left: 0px;
        }
        .layui-table, .layui-table-view {
            margin: 0px 0;
            margin-top: 10px;
        }
    </style>

</head>
<body>

<div class="layui-btn-group" style="display: none;">
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_add()">增加</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_update()">编辑</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_bat_update()">批量修改</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_delete()">删除</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_select_copy()">复制到其它表</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_other_copy()">从其它表复制</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_other_project_copy()">复制到其它项目</button>

    <!-- ES管理-->
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_create_es()">创建ES</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_delte_es()">删除ES</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_datatongbu_es()">数据同步ES</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_datatongbu_es_all()">全网数据同步ES</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_get_mapdata()">获取新增字段</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="code_auto_create()">代码生成</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="f_batup_up()">快速修改</button>


</div>

<table id="demo" lay-filter="test"></table>


<script src="/admin/plugin/layui/dist/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    var table = null;
    var $ = null;
    layui.use(['table','jquery'], function(){
        table = layui.table;
        $ = layui.$ //重点处

        //执行渲染
        table.render({
            id:"idTest",
            elem: '#demo' //指定原始表格元素选择器（推荐id选择器）
            ,height: "full-50" //容器高度
            ,cols:[[{checkbox: true},{field:"id",title:"字段id"},
                {field:"show_name",title: "字段中文名称",width:"220"}
                ,{field: "col_name",title:"字段名称",width:"120"}
                ,{field: "msg",title:"说明"}
                ,{field: "col_type",title:"字段类型",width:120}
                ,{field: "zygl_id",title:"表id",width:220}
                ,{field: "is_input",title:"录入是否显示"}
                ,{field: "is_list",title:"列表是否显示"}
                ,{field: "is_search",title:"是否默认查询"}
                ,{field: "length",title:"字段长度"}
                ,{field: "show_order",title:"排序号",width:120}]] //设置表头
            ,url:wwwurl+"/admin/api/FieldManagementController/list"
            ,where:{searchInputDtos:{"zygl_id":{key:"zygl_id",type:"6",value:top.data.zygl_id}}}
            ,contentType: 'application/json'
            ,method:"post"
            ,page:true
            ,limit:200
            ,toolbar: '.layui-btn-group'
            ,request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            headers: {
                token:localStorage.getItem("token")
            }
            ,parseData:function(res){
                return {
                    "code": "0", //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
            //,…… //更多参数参考右侧目录：基本参数选项
        });

        //监听行单击事件
        table.on('row(test)', function (obj) {
            //动态添加背景色
            if (obj.tr.hasClass('layui-table-click')) {
                obj.tr.removeClass('layui-table-click');    //删除背景色和
                obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
            } else {
                obj.tr.addClass('layui-table-click');
                obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
            }

            var index = obj.tr.data('index');
            var tableData = table.cache.idTest;//menu 是表格id
            var trHasClass = obj.tr.hasClass('layui-table-click');

            //循环判断class,选中checkbox
            layui.each(tableData, function (i, item) {
                if (trHasClass == true) {
                    if (index == i) {
                        item.LAY_CHECKED = true;
                    }
                } else {
                    if (index == i) {
                        item.LAY_CHECKED = false;
                    }
                }
            });
        });
    });


    function f_batup_up(){
        let btn = {btn: ['确定', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                let win = getTopIframe(layero);
                let data = win.getData();
                let i = top.layer.load();
                postBody("/admin/api/FieldManagementController/BatchModifyFields", data,function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        let ids = [];
        for(let a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        top.f_layer_open_get("/admin/html/fieldConfiguration/batupdate_list.html?zygl_id="+top.data.zygl_id+"&ids="+ids,"95%","80%",function () {

        },btn,"快速修改字段",{})
    }


    function code_auto_create(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        let ids = [];
        for(let a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        let btn = {btn: ['确定', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                let win = getTopIframe(layero);
                win.vm.submitData();
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/fieldConfiguration/code_auto.html?zygl_id="+top.data.zygl_id+"&ids="+ids,"65%","80%",function () {

        },btn,"代码生成工具",{})
    }

    function f_get_mapdata(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        let ids = [];
        for(let a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }

        layer.prompt({
            formType: 0,
            value: ' ',
            title: '请输入变量名称'
        },function(value, index, elem){
            let i = top.layer.load();
            post("/admin/api/FieldManagementController/getColumnsForAddData", {zygl_id:""+top.data.zygl_id,ids:""+ids,mapname:value},function (res) {
                top.layer.closeAll();
                layer.closeAll();
                layer.open({
                    type: 1,
                    area: ["400px", "600px"],
                    content: "<textarea class=\"layui-textarea\" rows='30' >"+res.data+"</textarea>" //这里content是一个普通的String
                });
            })

        });


    }


    function f_datatongbu_es_all(){
        layer.confirm('确定要同步数据至ES吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            let i = top.layer.load();
            post("/admin/api/FieldManagementController/dataSynchronizationAll", {tableId:""+top.data.zygl_id},function (res) {
                top.layer.closeAll();
                layer.closeAll();
                top.alert(res.msg);
            })
        }, function (index) {
            //按钮【按钮二】的回调
        });
    }

    //数据同步ES
    function f_datatongbu_es(){
        layer.confirm('确定要同步数据至ES吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            let i = top.layer.load();
            post("/admin/api/FieldManagementController/dataSynchronization", {zygl_id:""+top.data.zygl_id},function (res) {
                top.layer.closeAll();
                layer.closeAll();
                top.alert(res.msg);
            })
        }, function (index) {
            //按钮【按钮二】的回调
        });

    }

    function f_delte_es(){
        layer.confirm('确定要永久删除吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            let i = top.layer.load();
            post("/admin/api/FieldManagementController/deleteIndex", {index:""+top.data.zygl_id},function (res) {
                top.layer.closeAll();
                layer.closeAll();
                top.alert(res.msg);
            })
        }, function (index) {
            //按钮【按钮二】的回调
        });

    }

    function f_create_es(){
        let checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        let ids = [];
        for(let a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        let i = top.layer.load();
        post("/admin/api/FieldManagementController/createIndex", {ids:""+ids,zygl_id:""+top.data.zygl_id},function (res) {
            top.layer.close(i);
            top.alert(res.msg);
        })
    }

    function f_other_project_copy(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择字段进行复制");
            return;
        }
        let ids = [];
        for(let a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }
        let btn = {btn: ['确定', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                let win = getTopIframe(layero);
                let data = win.getData();
                if(data.length <= 0){
                    top.alert("请至少选择一个字段");
                    return ;
                }
                let i = top.layer.load();
                post("/admin/api/FieldManagementController/copyToOtherItems", {colIds:""+ids,toTableIds:""+data},function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    // table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/fieldConfiguration/copyColTree.html?ids="+ids,"40%","80%",function () {

        },btn,"复制到其它项目",{})
    }

    function f_other_copy(){
        let btn = {btn: ['确定', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                let win = getTopIframe(layero);
                let data = win.getData();
                if(data.length <= 0){
                    top.alert("请至少选择一个字段");
                    return ;
                }
                let i = top.layer.load();
                post("/admin/api/FieldManagementController/selectFieldsCopy", {ids:""+data,toTableId:""+top.data.zygl_id},function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/fieldConfiguration/treeAndFieldsSelect.html","40%","80%",function () {

        },btn,"从其它表复制",{})
    }

    function f_select_copy(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择字段进行复制");
            return;
        }
        let ids = [];
        for(let a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }

        let btn = {btn: ['确定', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                let win = getTopIframe(layero);
                let data = win.getData();
                if(data.length != 1){
                    top.alert("只能选择一个表");
                    return ;
                }
                let i = top.layer.load();
                post("/admin/api/FieldManagementController/selectFieldsCopy", {ids:""+ids,toTableId:""+data},function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    // table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/fieldConfiguration/treeSelect.html","40%","80%",function () {

        },btn,"字段复制",{})
    }

    function f_bat_update(){
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择字段进行复制");
            return;
        }
        let ids = [];
        for(let a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }

        let btn = {btn: ['确定', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                var i = top.layer.load();
                data.ids = ""+ids;
                postBody("/admin/api/FieldManagementController/batchModifyFieldInformation",data,function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/fieldConfiguration/input_batch.html","60%","80%",function () {

        },btn,"批量修改",{})
    }

    function f_add() {
        let btn = {btn: ['确定', '取消']
            ,yes: function(index, layero){
                console.log(layero);
                //按钮【按钮一】的回调
                var win = getTopIframe(layero);
                var data = win.getData();
                var i = top.layer.load();
                data.zygl_id = top.data.zygl_id;
                postBody("/admin/api/FieldManagementController/add",data,function (res) {
                    top.layer.close(i);
                    top.alert(res.msg);
                    data.col_name = "";
                    win.setData(data);
                    table.reload("idTest", {});
                })
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }};
        top.f_layer_open_get("/admin/html/fieldConfiguration/input.html","60%","80%",function () {

        },btn,"添加字段",{})
    }

    function f_update() {
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length != 1){
            top.alert("只能选择一条记录进行修改");
            return;
        }
        post("/admin/api/FieldManagementController/queryForId",{id:checkStatus.data[0].id},function (res) {
            let btn = {btn: ['确定', '取消']
                ,yes: function(index, layero){
                    console.log(layero);
                    //按钮【按钮一】的回调
                    var win = getTopIframe(layero);
                    var data = win.getData();
                    data.id = checkStatus.data[0].id;
                    var i = top.layer.load();
                    postBody("/admin/api/FieldManagementController/update",data,function (res) {
                        top.layer.close(i);
                        top.alert(res.msg);
                        table.reload("idTest", {});
                    })
                }
                ,btn2: function(index, layero){
                    //按钮【按钮二】的回调
                    //return false 开启该代码可禁止点击该按钮关闭
                }};
            top.f_layer_open_get("/admin/html/fieldConfiguration/input.html?v=1.1","60%","80%",function () {

            },btn,"修改字段",res.data);
        })

    }


    function f_delete() {
        var checkStatus = table.checkStatus('idTest'); //idTest 即为基础参数 id 对应的值
        if(checkStatus.data.length == 0){
            top.alert("请选择记录进行删除");
            return;
        }
        let ids = [];
        for(var a=0;a<checkStatus.data.length;a++){
            ids.push(checkStatus.data[a].id);
        }

        layer.confirm('确定要永久删除吗？', {
            btn: ['确定', '取消'] //可以无限个按钮
        }, function (index, layero) {
            load();
            post("/admin/api/FieldManagementController/delete",{ids:""+ids},function (res) {
                top.alert(res.msg);
                layer.closeAll();
                table.reload("idTest", {});
            })
        }, function (index) {
            //按钮【按钮二】的回调
        });

    }
</script>

</body>
</html>
